<?php
/**
 * 微校云主界面模型
 * Author: 孙武 QQ:1228746736
 * Date: 2017/11/1
 * Time: 10:37
 */

namespace Home\Model;
class HomeModel extends \Think\Model
{

    /**
     * 根据用户的openid获取用户信息
     * @param $openId
     * @return mixed
     */
    public function getUserInfoByOpenId($openId)
    {
        $map = array('usr_open_id' => $openId);
        return $this->where($map)->find();
    }

    /**
     * 根据用户的openid获取用户id
     * @param $openId
     * @return mixed
     */
    public function getUserIdByOpenId($openId)
    {
        $map = array('usr_open_id' => $openId);
        $res = $this->field('usr_id')->where($map)->find();
        return $res['usr_id'];
    }


    /**
     * 检查用户信息是否存在
     * @param $openId string 用户的openId
     * @return int 该用户的id
     */
    public function checkUserIsExist($openId)
    {
        $sql = "select usr_id as total from bus_user WHERE  usr_open_id='$openId'";
        $res = D()->query($sql);
        $checkRes = $res[0]['total'];
        if ($checkRes > 0) {
            return $checkRes;
        } else {
            return false;
        }

    }


    public function checkUserIsExistById($userId)
    {
        $sql = "select count(*) as total from bus_user WHERE  usr_open_id=$userId";
        $res = D()->query($sql);
        $checkRes = $res[0]['total'];
        if ($checkRes > 0) {
            return true;
        } else {
            return false;
        }
    }
}